# SPDX-FileCopyrightText: Copyright (c) {{cookiecutter.year}} {{cookiecutter.copyright_holder}}.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 4.0)
project({{ cookiecutter.project_slug }} LANGUAGES CXX)

# The CLI passes the selected SDK through CMAKE_PREFIX_PATH. Direct CMake
# builds can select it with the SDK environment variable instead.
if(DEFINED ENV{HOLOSCAN_SDK_ROOT})
  list(APPEND CMAKE_PREFIX_PATH "$ENV{HOLOSCAN_SDK_ROOT}")
endif()
# List every SDK module the application uses, such as inference or
# visualization; a component that is not listed is not found.
find_package(holoscan {{ cookiecutter.holoscan_version }} REQUIRED CONFIG COMPONENTS core)

add_executable({{ cookiecutter.project_slug }} main.cpp)
target_compile_features({{ cookiecutter.project_slug }} PRIVATE cxx_std_20)
target_link_libraries({{ cookiecutter.project_slug }} PRIVATE holoscan::core)
{%- if ',' in cookiecutter.language %}
# The executable stays in this folder's build directory, where the CLI starts
# the run commands from cpp/metadata.json.
set_target_properties({{ cookiecutter.project_slug }} PROPERTIES CXX_EXTENSIONS OFF)
{%- else %}
# Place the executable in the application's build directory, where the CLI
# starts the run commands from metadata.json.
set_target_properties({{ cookiecutter.project_slug }} PROPERTIES
  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/.."
  CXX_EXTENSIONS OFF)
{%- endif %}
install(TARGETS {{ cookiecutter.project_slug }} RUNTIME DESTINATION bin)

if(BUILD_TESTING)
{%- if ',' in cookiecutter.language %}
  # Keep tests in the C++ dependency scope. python/ adds the same folder for its
  # own tests, in another build directory.
  add_subdirectory(../tests "${CMAKE_CURRENT_BINARY_DIR}/tests")
{%- else %}
  # Keep tests in the C++ dependency scope and preserve their build directory.
  add_subdirectory(../tests "${CMAKE_CURRENT_BINARY_DIR}/../tests")
{%- endif %}
endif()
